package cn.yuan.xiaoyu.testmodule.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by yukuoyuan on 2017/9/7.
 */

public class CircleIndexView extends View {
    private int mBackgroudColor = Color.parseColor("#ff0000");
    private int centerY;
    private int centerX;

    public CircleIndexView(Context context) {
        this(context, null);
    }

    public CircleIndexView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CircleIndexView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        //中心坐标
        centerX = w / 2;
        centerY = h / 2;
        postInvalidate();
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = getPaint();
        canvas.drawColor(Color.WHITE, PorterDuff.Mode.CLEAR);
        canvas.drawCircle(centerX, centerY, 10, paint);
    }


    private Paint getPaint() {
        Paint paint = new Paint();
        paint.setColor(mBackgroudColor);
        paint.setStyle(Paint.Style.FILL);
        return paint;
    }

    /**
     * 设置背景颜色
     *
     * @param mBackgroudColor
     */
    public void setmBackgroudColor(int mBackgroudColor) {
        this.mBackgroudColor = mBackgroudColor;
        postInvalidate();
    }
}
